{#
    @profile_type
    @mail
    @user_profile
    @maillists:             All mail list accounts under same domain.
    @nonExistListEmails     Mail list addresses which already assigned but not exist
    @aliases                All mail list accounts under same domain.

    # profile_type == 'throttle'
    @throttleOfSender
    @throttleOfRecipient

    @[msg,]
#}

{% extends "layout.html" %}

{% from "macros/general.html" import
        display_subnav,
        set_account_status_img,
        display_input_cn,
        display_quota,
        display_input_employeeid,
        display_input_jobtitle,
        display_input_mobile,
        display_input_phone,
        display_account_status,
        display_reset_password,
        display_button_submit,
        with context
        %}

{% from "macros/msgHandlers.html" import userMsgHandler with context %}

{% block title %}{{ _('Edit account profile') }}{% endblock %}
{% block navlinks_active_domains %}class="active"{% endblock %}

{# User profile. #}

{% set user = user_profile[0] %}
{% set entries = user[1] %}

{% set mail = entries.get('mail')[0] %}
{% set cn = entries.get('cn', [ mail.split('@')[0] ])[0].decode('utf-8') %}
{% set username, cur_domain = mail.split('@', 1) %}
{% set employeeNumber = entries.get('employeeNumber', [''])[0].decode('utf-8') %}
{% set accountStatus = entries.get('accountStatus', ['disabled'])[0] %}

{# Get enabledService #}
{% if profile_type in ['general',] %}
    {% set enabledService = entries.get('enabledService', ['']) %}
{% endif %}

{% if profile_type == 'general' %}
    {% set jobtitle = entries.get('title', [''])[0].decode('utf-8') %}
    {% set mobile = entries.get('mobile', [''])[0] %}
    {% set telephoneNumber = entries.get('telephoneNumber', []) %}
    {% set mailQuota = '%d' % (entries.get('mailQuota', [0])[0] |int /1024/1024) %}
{% endif %}

{% block breadcrumb %}
    {% set crumbs = [
            (ctx.homepath + '/domains', _('All domains'),),
            (ctx.homepath + '/profile/domain/general/' + cur_domain, cur_domain,),
            (ctx.homepath + '/users/' + cur_domain, _('Users'),),
            (None, _('Profile of user:') + '&nbsp;' + mail,),
            ]
            %}
    {{ display_subnav(crumbs) }}
{% endblock %}

{% block main %}

{#-- Show system message --#}
{{ userMsgHandler(msg) }}

{% set navlinks = [
            ('general', _('General'), [true,]),
            ('password', _('Password'), [true,]),
            ]
            %}

    <div class="content-box">
        <div class="box-body">
            <div class="box-header clear">
                <ul class="tabs clear">
                    {% for nav in navlinks %}
                        {% if not false in nav[2] and not none in nav[2] %}
                            <li {% if profile_type == nav[0] %}class="active"{% endif %}><a href="{{ctx.homepath}}/profile/user/{{nav[0]}}/{{mail}}">{{ nav[1] }}</a></li>
                        {% endif %}
                    {% endfor %}
                </ul>

                <h2>{{ _('Profile of user:') }} {{ mail }}</h2>
            </div>

            <div class="box-wrap clear">

<form method="post" action="{{ctx.homepath}}/profile/user/{{profile_type}}/{{mail}}">

    {% if profile_type == 'general' %}
        <div class="columns clear">
            <div class="col2-3">
                {{ display_account_status(accountStatus) }}

                <div class="bt-space10"></div>
                {{ display_input_cn(cn) }}
                {{ display_quota(value=mailQuota, show_value_in_input='yes') }}

                <div class="bt-space10"></div>
                {{ display_input_employeeid(employeeNumber) }}
                {{ display_input_jobtitle(jobtitle) }}

                <div class="bt-space10"></div>
                {{ display_input_mobile(value=mobile) }}
                {{ display_input_phone(value=telephoneNumber) }}
            </div>{#-- .col2-3 --#}

        </div>{#-- .columns --#}

    {% elif profile_type == 'password' %}

        {{ display_reset_password(
                min_passwd_length=minPasswordLength,
                max_passwd_length=maxPasswordLength,
                show_confirmpw=true,
                )
                }}
    {% endif %}

    {{ display_button_submit() }}
</div>
</div>
</div>
</form>
{% endblock main %}
